﻿using Microsoft.AspNetCore.Mvc;
using MVC_System.DTO.Process;
using MVC_System.DTO.RawMaterial;
using Newtonsoft.Json;
using WMS_MAV;

namespace MVC_System.Controllers
{
    public class ProcessController : Controller
    {
        private readonly IConfiguration _configuration;
        public ProcessController(IConfiguration configuration)
        {
            _configuration = configuration;
        }
        public IActionResult ProcessHow()
        {
            return View();
        }
        public IActionResult ProcessAdd()
        {
            return View();
        }
        public IActionResult ProcessUpdate()
        {
            return View();
        }

        public async Task<ActionResult> ProcessShow(ProcessShowDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "RawApi/api/Process/ProcessShow?PageIndex=" + dto.PageIndex+ "&PageSize="+dto.PageSize+ "&ProcessNumebring="+dto.ProcessNumebring+ "&ProcessName="+dto.ProcessName+ "&ProcessStatus="+dto.ProcessStatus;
            var respomse = await  client.GetAsync(url);
            return Json(respomse);
        }
        public async Task<ActionResult> ProcessAddse(ProcessAddDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "RawApi/api/Process/ProcessAdd";
            var respomse = await client.PostAsync(url,dto.data);
            return Json(respomse);
        }
        public async Task<ActionResult> ProcessModel(ProcessMondelDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "RawApi/api/Process/ProcessMondel?id="+dto.id;
            var respomse = await client.GetAsync(url);
            return Json(respomse);
        }
        public async Task<ActionResult> ProcessUpdatese(ProcessUpdateDTO dto, string token)
        {
            HttpClientWrapper client = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "RawApi/api/Process/ProcessUpdate";
            string list = JsonConvert.SerializeObject(dto);
            var response = await client.PostAsync(url, list);
            return Json(response);
        }
		public async Task<ActionResult> ProcessDelete(ProcessDeleteDTO dto, string token)
		{
			HttpClientWrapper client = new HttpClientWrapper(token);
			string url = _configuration["Url"] + "RawApi/api/Process/ProcessDelete";
			string list = JsonConvert.SerializeObject(dto);
			var respomse = await client.PostAsync(url, list);
			return Json(respomse);
		}
		public async Task<ActionResult> ProcessDeletePi(ProcessDeletePiDTO dto, string token)
		{
			HttpClientWrapper client = new HttpClientWrapper(token);
			string url = _configuration["Url"] + "RawApi/api/Process/ProcessDeletepi";
			string list = JsonConvert.SerializeObject(dto);
			var respomse = await client.PostAsync(url, list);
			return Json(respomse);
		}
	}
}
